package com.ejia.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTabbedPane;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import java.util.ArrayList;

import javax.swing.JScrollPane;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.ejia.dao.BaseDao;
import com.ejia.pojo.fytype;
import com.ejia.pojo.money;
import com.ejia.pojo.user;
import com.ejia.server.CarServices;
import com.ejia.server.MoneyService;
import com.ejia.server.UserService;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;

public class Main extends JFrame {

	private JPanel contentPane;
	private static JTable table;
	private static ArrayList<money> moneys;
	private static ArrayList<user> users;
	private static ArrayList<fytype> fytypes;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main frame = new Main();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	
	
	public static void dateBind() {
		moneys = MoneyService.find();
		Object[][] data =new Object[moneys.size()][];
		for (int i = 0; i < data.length; i++) {
			data[i]=new Object[] {
					moneys.get(i).getMid(),moneys.get(i).getUserid().getUid(),moneys.get(i).getTypeid().getFyname(),moneys.get(i).getStartDate(),moneys.get(i).getEndDate(),moneys.get(i).getNumber()
			};
		}
		table.setModel(new DefaultTableModel(
				data,
				new String[] {
					"\u7F16\u53F7", "\u4E1A\u4E3B\u59D3\u540D", "\u8D39\u7528\u7C7B\u578B", "\u8D77\u59CB\u65E5\u671F", "\u7EC8\u6B62\u65E5\u671F", "\u6B20\u8D39\u91D1\u989D"
				}
			));
		table.getTableHeader().setFont(new Font("微软雅黑", 0, 24));
	}
	/**
	 * Create the frame.
	 */
	public Main() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/com/ejia/photo/客户管理系统.png")));
		setTitle("E家物业后台管理系统v2.2.4.34");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1410, 806);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("综合服务");
		mnNewMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
		menuBar.add(mnNewMenu);
		
		JMenu menu = new JMenu("疫情防控");
		menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
		menu.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new YQFK().setVisible(true);
				dispose();
			}
		});
		mnNewMenu.add(menu);
		
		JMenu menu_1 = new JMenu("小区公告");
		menu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
		menu_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new XQGG().setVisible(true);
				dispose();
			}
		});
		mnNewMenu.add(menu_1);
		
		JMenu mnNewMenu_1 = new JMenu("收费服务");
		mnNewMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
		menuBar.add(mnNewMenu_1);
		
		JMenu menu_2 = new JMenu("业主收费管理");
		menu_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
		menu_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new FYGL().setVisible(true);
				dispose();
			}
		});
		mnNewMenu_1.add(menu_2);
		
		JMenu menu_3 = new JMenu("收费类型管理");
		menu_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
		menu_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new SFLX().setVisible(true);
				dispose();
			
			}
		});
		mnNewMenu_1.add(menu_3);
		
		JMenu mnNewMenu_2 = new JMenu("业主服务");
		mnNewMenu_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
		menuBar.add(mnNewMenu_2);
		
		JMenu menu_4 = new JMenu("业主信息管理");
		menu_4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
		menu_4.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new YZXXGL().setVisible(true);
				dispose();
			}
		});
		mnNewMenu_2.add(menu_4);
		
		JMenu menu_5 = new JMenu("业主车辆管理");
		menu_5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
		menu_5.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new CLGL().setVisible(true);
				dispose();
			}
		});
		mnNewMenu_2.add(menu_5);
		
		JMenu mnNewMenu_3 = new JMenu("员工服务");
		mnNewMenu_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
		menuBar.add(mnNewMenu_3);
		
		JMenu menu_6 = new JMenu("员工信息管理");
		menu_6.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
		menu_6.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				new YGXXGL().setVisible(true);
				dispose();
			}
		});
		mnNewMenu_3.add(menu_6);
		
		JMenu mnNewMenu_4 = new JMenu("访客服务");
		mnNewMenu_4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
		menuBar.add(mnNewMenu_4);
		
		JMenu mnNewMenu_5 = new JMenu("个人信息");
		mnNewMenu_5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
		mnNewMenu_5.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				new GRXX().setVisible(true);
				dispose();
			}
		});
		menuBar.add(mnNewMenu_5);
		
		JMenu menu_7 = new JMenu("退出登录");
		menu_7.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
		menu_7.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				new login().setVisible(true);
				dispose();
			}
		});
		menuBar.add(menu_7);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		if (login.sf.equals("员工")) {
			mnNewMenu.hide();
			mnNewMenu_3.hide();
		}
		
		
		
		
		JPanel panel = new JPanel();
		panel.setBounds(15, 15, 1358, 643);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JPanel panel_1 = new JPanel();
		panel_1.setLayout(null);
		panel_1.setBorder(new LineBorder(Color.ORANGE, 3));
		panel_1.setBounds(62, 15, 340, 201);
		panel.add(panel_1);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon(Main.class.getResource("/com/ejia/photo/36school.png")));
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setBounds(17, 47, 114, 103);
		panel_1.add(label);
		
		JLabel label_1 = new JLabel("小区入住率");
		label_1.setFont(new Font("宋体", Font.PLAIN, 32));
		label_1.setBounds(146, 32, 179, 50);
		panel_1.add(label_1);
		
		JLabel label_2 = new JLabel("已入住");
		label_2.setHorizontalAlignment(SwingConstants.LEFT);
		label_2.setFont(new Font("宋体", Font.PLAIN, 24));
		label_2.setBounds(146, 110, 72, 40);
		panel_1.add(label_2);
		
		JLabel label_3 = new JLabel(""+UserService.count());
		label_3.setHorizontalAlignment(SwingConstants.CENTER);
		label_3.setFont(new Font("宋体", Font.PLAIN, 48));
		label_3.setBounds(236, 110, 37, 40);
		panel_1.add(label_3);
		
		JLabel label_4 = new JLabel("套");
		label_4.setFont(new Font("宋体", Font.PLAIN, 24));
		label_4.setBounds(288, 115, 37, 30);
		panel_1.add(label_4);
		
		JPanel panel_2 = new JPanel();
		panel_2.setLayout(null);
		panel_2.setBorder(new LineBorder(Color.ORANGE, 3));
		panel_2.setBounds(501, 15, 388, 201);
		panel.add(panel_2);
		
		JLabel label_5 = new JLabel("");
		label_5.setIcon(new ImageIcon(Main.class.getResource("/com/ejia/photo/29-车辆车位服务.png")));
		label_5.setBounds(6, 40, 159, 131);
		panel_2.add(label_5);
		
		JLabel label_6 = new JLabel("小区车位使用率");
		label_6.setHorizontalAlignment(SwingConstants.CENTER);
		label_6.setFont(new Font("宋体", Font.PLAIN, 30));
		label_6.setBounds(165, 28, 223, 58);
		panel_2.add(label_6);
		
		JLabel label_7 = new JLabel("已使用");
		label_7.setFont(new Font("宋体", Font.PLAIN, 26));
		label_7.setBounds(180, 106, 81, 49);
		panel_2.add(label_7);
		
		JLabel label_8 = new JLabel(""+CarServices.count());
		label_8.setFont(new Font("宋体", Font.PLAIN, 42));
		label_8.setBounds(311, 106, 46, 49);
		panel_2.add(label_8);
		
		JPanel panel_3 = new JPanel();
		panel_3.setLayout(null);
		panel_3.setBorder(new LineBorder(Color.ORANGE, 3));
		panel_3.setBounds(988, 15, 340, 201);
		panel.add(panel_3);
		
		JLabel label_9 = new JLabel("");
		label_9.setIcon(new ImageIcon(Main.class.getResource("/com/ejia/photo/物业缴费mdpi.png")));
		label_9.setBounds(0, 35, 119, 138);
		panel_3.add(label_9);
		
		JLabel label_10 = new JLabel("小区物业缴费率");
		label_10.setFont(new Font("宋体", Font.PLAIN, 30));
		label_10.setBounds(115, 35, 210, 45);
		panel_3.add(label_10);
		
		JLabel label_11 = new JLabel("未缴费金额:"+MoneyService.arrears());
		label_11.setHorizontalAlignment(SwingConstants.CENTER);
		label_11.setFont(new Font("宋体", Font.PLAIN, 24));
		label_11.setBounds(115, 105, 210, 51);
		panel_3.add(label_11);
		
		JLabel label_12 = new JLabel("共计:"+MoneyService.sum());
		label_12.setHorizontalAlignment(SwingConstants.RIGHT);
		label_12.setFont(new Font("宋体", Font.PLAIN, 24));
		label_12.setBounds(115, 168, 210, 33);
		panel_3.add(label_12);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 317, 1333, 311);
		panel.add(scrollPane);
		
		table = new JTable();
		dateBind();
		table.setRowHeight(40);
		table.setFont(new Font("宋体", Font.PLAIN, 26));
		scrollPane.setViewportView(table);
		
		JLabel label_13 = new JLabel("欠费用户信息列表");
		label_13.setFont(new Font("宋体", Font.PLAIN, 42));
		label_13.setBounds(0, 255, 340, 61);
		panel.add(label_13);
		
		JLabel label_14 = new JLabel("欢迎您："+login.sf+login.cname);
		label_14.setBounds(1111, 673, 262, 41);
		contentPane.add(label_14);
		label_14.setFont(new Font("宋体", Font.PLAIN, 26));
		
		
		setLocationRelativeTo(null);
	}
}
